<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    #div1 {
      position: absolute;
      left: 0;
      top: 0;
      width: 100px;
      height: 100px;
      background: red;
    }
  </style>
</head>
<body>
<div id="div1"></div>
<script>
  window.onload = function () {
    var oDiv = document.getElementById('div1');
    oDiv.onmousedown = function (e) {
      var ev = e || window.event;
      var disX = ev.clientX - this.offsetLeft;
      var disY = ev.clientX - this.offsetTop;
      if (oDiv.setCapture) {
        oDiv.setCapture();
      }
      document.onmouseover = function (ev) {
        var ev2 = ev || window.event;
        oDiv.style.left = ev2.clientX - disX + 'px';
        oDiv.style.top = ev.clientY - disY + 'px';
      };
      document.onmouseup = function () {
        document.onmouseover = document.onmouseup = null;
        if(oDiv.releaseCapture){
            oDiv.releaseCapture();
        }
      }
      return false;
    }
  }
</script>
</body>
</html>